#include "test_structure_index.hpp"

void test_created_chained_ligne()
{
  bool ok(true);
  chained_ligne c_l;
  string s("");
  created_chained_ligne(c_l);

  if(c_l != NULL)
    ok=false;

  if(ok)
    cout << "TEST : created_chained_ligne -----------> OK" << endl;
  else
    cout << "TEST : created_chained_ligne -----------> NOK" << endl;

  cout << "Saisir une lettre" << endl;
  cin >> s;
}

void test_created_chained_index()
{
  bool ok(true);
  chained_index c_l;
  string s("");

  created_chained_index(c_l);

  if(c_l != NULL)
    ok=false;

  if(ok)
    cout << "TEST : created_chained_index -----------> OK" << endl;
  else
    cout << "TEST : created_chained_index -----------> NOK" << endl;

  cout << "Saisir une lettre" << endl;
  cin >> s;
}

void test_structure_index()
{
  bool ok(true);
  chained_index c_i,lecture;
  string tab[10],continu("");
  int tab_nb[10][3];

  created_chained_index(c_i);

  for(int i=0 ; i < 10 ; ++i)
    {
      for(int j=0 ; j < 3 ; ++j)
	tab[i]+=(char)(97+rand()%26);
      add_word_index(c_i,tab[i]);
    }
  lecture=c_i;

  for(int i=0 ; i < 10 && ok ; ++i)
    {
      if(tab[i] != lecture->word)
	ok=false;
      lecture=lecture->next;
    }

  if(ok)
    cout << "TEST : add_word_index ------------------> OK" << endl;
  else
    cout << "TEST : add_word_index ------------------> NOK" << endl;

  cout << "Saisir une lettre" << endl;
  cin >> continu;

  lecture=c_i;

  if(ok)
    {
      chained_ligne lecture_l;
      created_chained_ligne(lecture_l);

      for(int i=0 ; i < 10 ; ++i)
	{
	  for(int j=0 ; j < 3 ; ++j)
	    {
	      tab_nb[i][j]=rand()%10;
	      add_number_ligne(c_i,tab[i],tab_nb[i][j]);
	    }
	}

      for(int i=0 ; i < 10 && ok ; ++i)
	{
	  lecture_l=lecture->ligne;
	  for(int j=0 ; j < 3 && ok ; ++j)
	    {
	      if(lecture_l->ligne != tab_nb[i][j])
		ok=false;
	      lecture_l=lecture_l->next;
	    }
	  lecture=lecture->next;
	}

    }

  if(ok)
    cout << "TEST : add_number_ligne ----------------> OK" << endl;
  else
    cout << "TEST : add_number_ligne ----------------> NOK" << endl;

  cout << "Saisir une lettre" << endl;
  cin >> continu;

  delete_all_index(c_i);

  cout << "TEST : delete_all_index ----------------> PROCEED" << endl;

  cout << "Saisir une lettre" << endl;
  cin >> continu;
}

int main()
{
  srand(time(NULL));

  test_created_chained_ligne();
  test_created_chained_index();

  test_structure_index();

  return 0;
}
